package io.shardingjdbc.example.orchestration.spring.boot.jpa.web;

import io.shardingjdbc.example.orchestration.spring.boot.jpa.entity.Order;
import io.shardingjdbc.example.orchestration.spring.boot.jpa.entity.OrderItem;
import io.shardingjdbc.example.orchestration.spring.boot.jpa.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/add/{userId}")
    public HttpStatus add(@PathVariable int userId) {
        orderService.add(userId);
        return HttpStatus.OK;
    }
    @RequestMapping("/order/{userId}")
    public List<Order> selectOrder(@PathVariable int userId){
       return orderService.selectOrder(userId);
    }
    @RequestMapping("/orderItem/{userId}")
    public List<OrderItem> selectOrderItem(@PathVariable int userId){
        return orderService.selectOrderItem(userId);
    }

    @RequestMapping("/delete")
    public HttpStatus delete() {
        orderService.delete();
        return HttpStatus.OK;
    }
    @RequestMapping("/test")
    public String helloworld(){
        return "hello world!";
    }
}
